package org.example.judge_common.util;

import org.example.judge_common.hander.RetrunMsgException;

import java.util.Scanner;

public enum CompileUnit {

    JAVA(CompileUnit.JAVA_SCALE),

    GCC(CompileUnit.GCC_SCALE),

    C(CompileUnit.C_SCALE),

    PYTHON(CompileUnit.PYTHON_SCALE);


    public static CompileUnit get(String language) throws RetrunMsgException {
        if (language.equalsIgnoreCase("java")) {
            return JAVA;
        } else if (language.equalsIgnoreCase("python")) {
            return PYTHON;
        } else if (language.equalsIgnoreCase("c")) {
            return C;
        } else if (language.contains("c++") || language.contains("C++")) {
            return GCC;
        }
        throw new RetrunMsgException("存在无法识别的编译语言:" + language);
    }

    private static final int JAVA_SCALE = 0;
    private static final int GCC_SCALE = 1;
    private static final int C_SCALE = 2;
    private static final int PYTHON_SCALE = 3;

    private final int scale;

    CompileUnit(int s) {
        this.scale = s;
    }

    public int getScale() {
        return scale;
    }

    public String fileName() {
        return switch (this.scale) {
            case JAVA_SCALE -> "Main.java";
            case GCC_SCALE -> "Main.cpp";
            case C_SCALE -> "Main.c";
            case PYTHON_SCALE -> "Main.py";
            default -> null;
        };
    }
}
